﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace MediaRegister
{
    /// <summary>
    /// 
    /// </summary>
    public partial class FormKöpData : Form
    {
        private struct köpdata
        {
            public string Nr;
            public string Modell;
            public string SerieNr;
            public string Specifikation;
            
        }
        
        /// <summary>
        /// 
        /// </summary>
        public int data1;
        
        public FormKöpData()
        {
            InitializeComponent();
        }

       
        private void button111_Click(object sender, EventArgs e)
        {
            köpdata datak;

            datak.Nr = textBox1.Text;
            datak.Modell = textBox2.Text;
            datak.SerieNr = textBox3.Text;
            datak.Specifikation = textBox4.Text;
            FileStream fs1 = new FileStream(@"M:\KöpData.txt", FileMode.Append, FileAccess.Write);
            StreamWriter sr1 = new StreamWriter(fs1);
            sr1.WriteLine(datak.Nr + " , " + datak.Modell + " , " + datak.SerieNr + " , " + datak.Specifikation);
            foreach (Control t in this.Controls)
                if (t is TextBox)
                    t.Text = " ";
            sr1.Close();
        }

        private void button222_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            String s1;
            if (File.Exists(@"M:\KöpData.txt"))
            {
                FileStream fs1 = new FileStream(@"M:\KöpData.txt", FileMode.Open, FileAccess.Read);
                StreamReader sr1 = new StreamReader(fs1);
                s1 = sr1.ReadLine();
                while (s1 != null)
                {
                    listBox1.Items.Add(s1);
                    s1 = sr1.ReadLine();


                }
                sr1.Close();
            }

            else
            {
                MessageBox.Show("Finns ingen fil att visa");
            }
        }

        
    }
}
